import request from "../utils/request"

/**
 * 查询部门列表
 * @returns 
 */
export const getDepts = function () {
  return request.get(`/sys/dept/all`)
}

/**
 * 查询部门绩效列表
 */
export const getDeptWages = function () {
  return request.get(`/salary/dept/wages`)
}

/**
 * 保存部门绩效
 * @param deptWage 
 */
export const saveDeptWage = function(deptWage: any) {
  return request.post('/salary/dept/wage/save', deptWage)
}

/**
 * 删除部门绩效
 * @param id 
 */
export const deleteDeptWage = function(id: number) {
  return request.delete(`/salary/dept/wage/delete/${id}`)
}

/**
 * 查询部门员工工资列表
 * @param deptId 
 */
export const getEmployeeWagesOfDept = function(deptId: number) {
  return request.get(`/salary/employee/wage/dept/${deptId}`)
}

/**
 * 删除员工工资信息
 * @param id 
 */
export const deleteEmployeeWage = function(id: string) {
  return request.delete(`/salary/employee/wage/delete/${id}`)
}

/**
 * 查询部门员工列表
 * @param id 
 * @returns 
 */
export const getUsersOfDept = function (id: number) {
  return request.get(`/user/list/dept/${id}`)
}

/**
 * 添加部门信息
 * @param dept
 */
export const saveDept = function (dept: any) {
  return request.post('/sys/dept/save', dept)
}

/**
 * 删除部门
 * @param id 
 * @returns 
 */
export const deleteDept = function (id: number) {
  return request.delete(`/sys/dept/delete/${id}`)
}

/**
 * 获取全部任务
 * @returns 
 */
export const getTaskAll = function () {
  return request.get('/salary/tasks')
}


/**
 * 更改任务状态
 * @param id 
 * @param state 
 */
export const changeTaskState = function(_id: number, _state: number) {
  return request.post('/salary/task/state/change', {id: _id, state: _state})
}

/**
 * 删除工资任务
 * @param id 
 */
export const deleteTaskById = function(id: number) {
  return request.post(`/salary/task/delete/${id}`)
}

/**
 * 获取部门工资列表
 */
export const getTaskDepts = function() {
  return request.get('/salary/task/depts')
}

/**
 * 创建工资任务
 */
export const createWageTask = function () {
  return request.get('/salary/wage/task/create')
}

/**
 * 保存工资任务
 * @param task 
 * @returns 
 */
export const saveWageTask = function(task: any) {
  return request.post('/salary/wage/task/save', task)
}

/**
 * 获取任务下部门任务列表
 * @param taskId 
 */
export const getDeptTasks = function(taskId: number) {
  return request.get(`/salary/task/dept/items?taskId=${taskId}`)
}

/**
 * 获取任务信息
 * @param taskId 
 */
export const getTaskById = function(taskId: number) {
  return request.get(`/salary/task/info/${taskId}`)
}

/**
 * 初始化部门任务
 * @param taskId 
 */
export const getDeptSalaries = function(taskId: string) {
  return request.post(`/salary/dept/salaries/${taskId}`)
}

/**
 * 保存部门员工绩效列表
 * @param salaries 
 */
export const saveDeptSalaries = function(taskId: string, salaries: any) {
  return request.post(`/salary/dept/salaries/save/${taskId}`, salaries)
}

/**
 * 查询绩效工资任务列表
 * @param state 
 */
export const getWageTasks = function(state: number) {
  return request.get(`/salary/tasks/list/${state}`)
}

/**
 * 计算状态
 * @param st 
 * @returns 
 */
export const stateType = function(st: number) {
  switch(st){
    case -1: return {type: 'danger', txt: '锁定'}
    case 1: return {type: 'primary', txt: '发布中'}
    case 2: return {type: 'success', txt: '已完成'}
    default: return {type: 'info', txt: '未发布'}
  }
}

/**
 * 查询用户的工资信息
 * @param userId 
 */
export const getUserWage = function(userId: string) {
  return request.get(`/salary/wage/info/${userId}`)
}

/**
 * 保存工资信息
 * @param wage 
 */
export const saveWage = function(wage: any) {
  return request.post('/salary/wage/save', wage)
}

/**
 * 导出指定任务的工资列表
 * @param taskId 
 */
export const getWagesOfTask = function(taskId: string) {
  return request.get(`/salary/wage/list/${taskId}`)
}

/**
 * 获取指定任务的部门任务信息
 * @param taskId 
 */
export const getDeptWagesOfTask = function(taskId: number) {
  return request.get(`/salary/dept/wage/${taskId}`)
}

/**
 * 重置部门任务
 * @param taskId 
 */
export const resetDetpTask = function(taskId: string) {
  return request.post(`/salary/dept/task/reset/${taskId}`)
}

/**
 * 获取进行中的任务列表
 */
export const getCurrentTasks = function() {
  // return request.get('/salary/current/tasks')
  return request.get('/salary/tasks')
}

/**
 * 获取任务中干部任务列表
 * @param taskId 
 */
export const getCadreTasks = function(taskId: number) {
  return request.get(`/salary/cadres/task/${taskId}`)
}

/**
 * 保存干部绩效列表
 * @param cadres 
 * @returns 
 */
export const saveCadreMerits = function(cadres: any) {
  return request.post('/salary/cadres/save', cadres)
}

/**
 * 初始化部门员工工资
 * @param deptId 
 * @returns 
 */
export const initDeptStaffWage = function(deptId: any) {
  return request.post(`/salary/wage/init/dept/${deptId}`)
}